package com.example.barcodeapp.ui.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.barcodeapp.R;
import com.example.barcodeapp.common.Constants;
import com.example.barcodeapp.ui.home.bean.JiaoShiXiangQingBean;

import java.util.List;

public class JiaoShiXiangQingAdapter extends RecyclerView.Adapter<JiaoShiXiangQingAdapter.ViewHolder> {
    public List<JiaoShiXiangQingBean.DataEntity.KechenEntity> list;
    public Context context;


    public JiaoShiXiangQingAdapter(Context context) {
        this.context = context;
    }

    public JiaoShiXiangQingAdapter( Context context,List<JiaoShiXiangQingBean.DataEntity.KechenEntity> list) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.adapter_xileiw, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Glide.with(context).load(Constants.Base_TPUrl2 +list.get(position).getList().get(position).getImageurl()).into( holder.xieleiImg);
        holder.xileiName.setText(list.get(position).getList().get(position).getCoursename());
        holder.textView9.setText(list.get(position).getList().get(position).getDesc());
        holder.textView11.setText(list.get(position).getList().get(position).getPrice());
        holder.xileiKecheng.setText(list.get(position).getList().get(position).getKeshi()+"课");
        holder.textView10.setText("讲师："+list.get(position).getList().get(position).getJianshi());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView xieleiImg;
        private TextView textView11;
        private TextView likegoumai;
        private TextView textView9;
        private TextView textView10;
        private TextView textView8;
        private TextView xileiName;
        private ImageView imageView3;
        private TextView xileiKecheng;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            xieleiImg = (ImageView) itemView.findViewById(R.id.xielei_img);
            textView11 = (TextView) itemView.findViewById(R.id.textView11);
            likegoumai = (TextView) itemView.findViewById(R.id.likegoumai);
            textView9 = (TextView) itemView.findViewById(R.id.textView9);
            textView10 = (TextView) itemView.findViewById(R.id.textView10);
            textView8 = (TextView) itemView.findViewById(R.id.textView8);
            xileiName = (TextView) itemView.findViewById(R.id.xilei_name);
            imageView3 = (ImageView) itemView.findViewById(R.id.imageView3);
            xileiKecheng = (TextView) itemView.findViewById(R.id.xilei_kecheng);
        }
    }
}
